package org.example.springcloud.service;

import feign.hystrix.FallbackFactory;
import org.example.springcloud.pojo.Dept;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.List;

/**
 * @author zfj
 * @date 2022/2/18 -12:14
 */
//降级
@Component
public class DeptClientServiceFallbackFactory implements FallbackFactory {
	@Override
	public DeptClientService create(Throwable throwable) {
		return new DeptClientService() {
			@Override
			public Dept queryById(Long id) {
				return new Dept()
						.setDeptno(id)
						.setDname("id=>"+id+",没有对应的信息，客户端提供了降级的信息，这个服务现在已经被关闭")
						.setDb_source("没有数据");
			}

			@Override
			public List<Dept> queryAll() {
				return null;
			}

			@Override
			public boolean addDept(Dept dept) {
				return false;
			}
		};
	}
}
